{% extends "base.html" %}
  {% block content %}
    {% from "forms/macros.html" import render_field_busqueda %}
    <SCRIPT LANGUAGE="JavaScript">
	
		url = "/permisos/modificar/ID/"
		url2 = "/permisos/eliminar/ID/"
		url3 = "/permisos/consultar/ID/"
		
		id_href = 'modificar'
		id_href2 = 'eliminar'
		id_href3 = 'consultar'
 
		function obtener_id(id) {
        	link = document.getElementById(id_href)
        	link2 = document.getElementById(id_href2)
        	link3 = document.getElementById(id_href3)
        	new_url = url.replace('ID', id)
        	new_url2 = url2.replace('ID', id)
        	new_url3 = url3.replace('ID', id)
        	link.href = new_url
        	link2.href = new_url2
        	link3.href = new_url3
        
		}
		function pregunta(){
    		if(confirm('Esta seguro de que desea eliminar el permiso?')){
    			return true;
    		}else{
    			return false;
    		}
    	}
	</SCRIPT>
	<h2> Administracion de Permisos </h2>
    <form method="POST" action={{url_for('permisos.administracion_permiso')}} class="form">
                {{ form.csrf_token }} 
    <div style="overflow:auto; width: 770px; height: 550px; " >  
         <table>
         <tr >
                 <th></th>
                         <th>  <label>Filtro</label> </th>
                 <th>{{ render_field_busqueda(form.nombre, class="input text") }}</th>
     		 	<th>{{ render_field_busqueda(form.entidad, class="input text") }}</th>
     		 	<th> </th>
        </tr >                         
                <tr >
                         <th></th>
                        <th> <center>ID </center></th>
			      		<th> <center> NOMBRE </center></td>
			      		<th> <center> DESCRIPCION </center></td>
			      		<th> <center> ENTIDAD </center></td>
        </tr >                 
                {% for permiso in permisos %}                 
                   <tr >
	                  <th><input type = "radio" name = "seleccionado" id="select" onchange="obtener_id({{permiso.id}})"></th>
	                  <td> <center>{{ permiso.id }} </center></td>
	      			  <td> <center>{{ permiso.nombre }} <center></td>
	      			  <td> <center>{{ permiso.descripcion }} <center></td>
	      			  <td> <center>{{ permiso.entidad.nombre}} <center></td>
                    </tr>                  
                {% endfor %}
               
        </table>
       </div> 
       </br>
        <div class="buttons">
                <button type="submit" class="button green">
                Buscar
                </button>
		        <button type="submit" class="button green">
		                <a href="{{ url_for('permisos.crear_permiso') }}">Crear</a>
		        </button>
		        <button type="submit" class="button green">
		                <a href="" id="modificar">Modificar</a>
		        </button>
		        <button type="submit" class="button green">
		                <a href="" id="consultar">Consultar</a>
		        </button>
		        <button type="submit" onclick =  "return pregunta()">
		                <a href="" id="eliminar">Eliminar</a>
		        </button>
		</div> 
                 
    </form>
   
   
  {% endblock %}